document.write("<script type='text/javascript' src='"+root+"js/common/headerUtil.js?"+version+"'></script>");
var rootPath = getRootPath();
var data2
var isPhone =isPhoneScreen();
$(function() {	
	 headerMenuShow();//头部 导航  外部引用代码
	 login_reg($('#headerImg'))//头部 导航  外部引用代码
	    
	  var year = new Date().getFullYear(); //获取当前年份
	    $("#time1").text(year)
//	headerMenuShow($("#commonApplication"));
//	$(".headerImg").click(goLogin);
	
	$.ajax({ //获取模块信息
			url : rootPath + '/listAllTitle',
			type : 'POST',
			contentType : 'application/json',
			dataType : 'json',
			success : function(successdata) {	     											
				$.ajax({ //用户获取头像
					url: rootPath + '/user/queryUserself',
				    type: 'GET',
				    contentType: 'application/json;charset=UTF-8',
				    success: function (data) {				    					    	
				     	if(data.returnCode == '0000') { //获取头像成功				     		
				     		var user = data.returnObject;
				     		console.log(user)
				      		var ui =document.getElementById("operate");
//				      			var img =document.getElementById("userimg");
			      			ui.style.display="none"
				      		/*	img.style.display="block";*/
				      			$("#helpheader").attr("src", user.headimgurl == "" ? "../../images/moren.png" : rootPath + "/file/viewimg?fileName=" + (user.headimgurl) + "&type=1");
				     		
							$(".login_btn").hide();
							
				     		var user = data.returnObject;	     		
				     		data2 = {
				     			      "nickname": user.uname,
				     			      "avatar": user.headimgurl == "" ? "../../images/moren.png" : rootPath + "/file/viewimg?fileName=" + (user.headimgurl) + "&type=1",
				     			      "openid": user.uid,
				     			 }	 
				     		help_show_login(successdata);
				       	}else{
				       		help_show(successdata);
				       	}
				    },
				    error: function () {
				    	
				    }
				});
				
				
			},
			error : function() {
			}
});
				

	
	
})
//登录页面
function goLogin() {	
var service=encodeURIComponent(rootPath+'/normal/pages/help/help.html');
	var url = "../guest/login.html?service="+service;	
	document.location.href = url;
}

function handleOnclick(obj){	//带ID跳转吐个槽
	var productId=obj.id;
	Tucao.request(productId, data2);
}


function help_show_login(data){ //登录成功情况下的模块
	if(data.state=="1"){
		var length = data.dataObject.length;
		var tr;
		for (var i = 0; i < length; i++) {	
			
			console.log(data.dataObject[i].sort)
		if(data.dataObject[i].sort=="1"){
			var productId = data.dataObject[i].productid; 
			console.log(data.dataObject[i].productid)
			 var helpservice = document.createElement("div");
			 helpservice.classList.add("hx");
			 helpservice.classList.add("col-md-3");
			 helpservice.classList.add("col-xs-4");	
			 var helpservice2 = document.createElement("div");
			 helpservice2.classList.add("product");
			 helpservice.appendChild(helpservice2);
			 var helplj = document.createElement("a");
			helplj.setAttribute("onclick","handleOnclick(this)");
			helplj.setAttribute("id",productId);
			 helpservice2.appendChild(helplj);
			 var modulename= document.createElement("span");
			 modulename.classList.add("module_name");
			 modulename.innerText=data.dataObject[i].name;
			 var helplimg = document.createElement("img");
			 helplimg.setAttribute("src",rootPath+"/file/viewimg?fileName="+data.dataObject[i].imgurl+"&type=4");				
			 helplj.appendChild(modulename);	
			 helplj.appendChild(helplimg);			 			   
			 var help_service =document.getElementById("help_services");
			 
			 help_service.appendChild(helpservice);
			 
			 
		}else{
			var	 productId = data.dataObject[i].productid; 
			 var helpservice = document.createElement("div");
			 helpservice.classList.add("hx");
			 helpservice.classList.add("col-md-3");
			 helpservice.classList.add("col-xs-4");	
			 var helpservice2 = document.createElement("div");
			 helpservice2.classList.add("product");
			 helpservice.appendChild(helpservice2);
			 var helplj = document.createElement("a");
			 helplj.setAttribute("onclick","handleOnclick(this)");
			 helplj.setAttribute("id",productId);
			 helpservice2.appendChild(helplj);
			 var modulename= document.createElement("span");
			 modulename.classList.add("module_name");
			 modulename.innerText=data.dataObject[i].name;
			 var helplimg = document.createElement("img");
			 helplimg.setAttribute("src",rootPath+"/file/viewimg?fileName="+data.dataObject[i].imgurl+"&type=4");				
			 helplj.appendChild(modulename);
			 helplj.appendChild(helplimg);			 			   
			 var help_service =document.getElementById("operation_services");
			 
			 help_service.appendChild(helpservice);
		}	
			
		}
		$("#helpmodule").empty();
		$("#helpmodule").append(tr);
	}
	
}

function help_show(data){
	if(data.state=="1"){
		var length = data.dataObject.length;
		var tr;
		for (var i = 0; i < length; i++) {	
			console.log(data.dataObject[i].sort)
		if(data.dataObject[i].sort=="1"){
			 var helpservice = document.createElement("div");
			 helpservice.classList.add("hx");
			 helpservice.classList.add("col-md-3");
			 helpservice.classList.add("col-xs-4");	
			 var helpservice2 = document.createElement("div");
			 helpservice2.classList.add("product");
			 helpservice.appendChild(helpservice2);
			 var helplj = document.createElement("a");
			 helplj.setAttribute("href",data.dataObject[i].tucaourl);
			 helplj.setAttribute("target","_blank");
			 helpservice2.appendChild(helplj);
			 var modulename= document.createElement("span");
			 modulename.classList.add("module_name");
			 modulename.innerText=data.dataObject[i].name;
			 var helplimg = document.createElement("img");
			 helplimg.setAttribute("src",rootPath+"/file/viewimg?fileName="+data.dataObject[i].imgurl+"&type=4");				
			 helplj.appendChild(modulename);
			 helplj.appendChild(helplimg);	
			 
			 var help_service =document.getElementById("help_services");
			 
			 help_service.appendChild(helpservice);
			 
		}else{
			 var helpservice = document.createElement("div");
			 helpservice.classList.add("hx");
			 helpservice.classList.add("col-md-3");
			 helpservice.classList.add("col-xs-4");	
			 var helpservice2 = document.createElement("div");
			 helpservice2.classList.add("product");
			 helpservice.appendChild(helpservice2);
			 var helplj = document.createElement("a");
			 helplj.setAttribute("href",data.dataObject[i].tucaourl);
			 helplj.setAttribute("target","_blank");
			 helpservice2.appendChild(helplj);
			 var modulename= document.createElement("span");
			 modulename.classList.add("module_name");
			 modulename.innerText=data.dataObject[i].name;
			 var helplimg = document.createElement("img");
			 helplimg.setAttribute("src",rootPath+"/file/viewimg?fileName="+data.dataObject[i].imgurl+"&type=4");				
			 helplj.appendChild(modulename);
			 helplj.appendChild(helplimg);			 			   
			 var help_service =document.getElementById("operation_services");
			 
			 help_service.appendChild(helpservice);
		}	
			
		}
		$("#helpmodule").empty();
		$("#helpmodule").append(tr);
	}
	
}
